package com.netkiller.mailmonitor.dao;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import org.springframework.stereotype.Component;

import com.netkiller.mailmonitor.entity.AppUser;
import com.netkiller.mailmonitor.entity.LogMessage;

@Component
public class LogMessageDao  extends AbstractDao<LogMessage>{
	
	public List<LogMessage> getLastTenLogs(){
		List<LogMessage> objList = new ArrayList<LogMessage>();
		PersistenceManager pm = super.getPersistenceManager();		
		Query query = pm.newQuery(LogMessage.class);
		query.setOrdering("date desc");
		query.setRange(0, 10);
		try {
			List<LogMessage> results = (List<LogMessage>) query.execute();
			if (!results.isEmpty()) {
				objList.addAll(pm.detachCopyAll(results));
			}
		} finally {
			query.closeAll();
			pm.close();
		}
		return objList;
	}

}
